Skip to content

Add CMD_HELP UDTF for fast CL command hover documentation#71

Open
bobcozzi wants to merge 1 commit into
IBM:mainfrom
bobcozzi:feature/cmd-help-udtf
Open

Add CMD_HELP UDTF for fast CL command hover documentation#71
bobcozzi wants to merge 1 commit into
IBM:mainfrom
bobcozzi:feature/cmd-help-udtf

Conversation

@bobcozzi

Copy link
Copy Markdown
Contributor

Summary

This PR adds a fast primary path for CL command hover documentation using a SQL Table Function (CMD_HELP) that wraps the IBM i QUHRHLPT API. The existing GENCMDDOC-based path is preserved as a fallback.


Problem

Hovering over a CL command or parameter currently calls GENCMDDOC, which:

  • Requires the Db2 for i JVM to be warm (cold-start adds 15–30 seconds)
  • Generates a full HTML document and writes it to the IFS
  • Downloads the file over a second SSH round-trip
  • Runs through the ileQueue, serializing behind any active compile

Even with a warm JVM, GENCMDDOC typically takes 5–15 seconds, making the hover feature impractical for everyday use. Many users disable it entirely via general.displayCommandDocumentation.


Solution

A new CmdHelpChecker IBMiComponent installs a C++ service program (CMDHELP) and SQL Table Function (CMD_HELP) into the connection's tempLibrary on first connect. The UDTF wraps QUHRHLPT directly and returns HTML help text for a specific parameter keyword or the entire command — all via a single SQL call.

Signature:

CMD_HELP(library VARCHAR(10), cmd VARCHAR(10), helpid VARCHAR(6000))
RETURNS TABLE (HELP_XML CLOB(16M))

Pass the command name as helpid for command-level help, or a parameter keyword (e.g. MSGID) for parameter-level help. Despite the column name, the returned content is HTML.

The hover provider now:

  1. Calls CMD_HELP first — returns in under a second, no JVM required
  2. Converts the returned HTML to Markdown using NodeHtmlMarkdown
  3. Falls back to the existing GENCMDDOC path if CMD_HELP is unavailable or returns no data

Files Changed

File Change
client/src/components/cmdHelp/cmdHelpChecker.ts New IBMiComponent — auto-installs/updates the UDTF on connect
client/src/components/cmdHelp/cmdHelpCppSource.ts Embedded base64-encoded C++ source for CMDHELP service program
client/src/components/cmdHelp/cmdHelpSqlSource.ts SQL DDL that creates/replaces the CMD_HELP UDTF
client/src/gencmddoc.ts New getCLDocParam() method — queries CMD_HELP and returns Markdown
client/src/extension.ts Registers CmdHelpChecker; adds getCLDocParam LSP request handler
server/src/instance.ts New getCLDocParam() LSP request helper
server/src/providers/hover.ts CMD_HELP fast path with GENCMDDOC fallback
client/src/components/syntaxChecker/checker.ts Minor: DBGVIEW(*LIST)DBGVIEW(*NONE)

Behaviour

  • If CMD_HELP is installed and returns data → hover shows immediately with a "View Full Documentation" link that triggers GENCMDDOC on demand
  • If CMD_HELP is not yet installed, or SQL runner unavailable → silently falls back to existing GENCMDDOC path (no regression)
  • The C++ source is base64-encoded in the TypeScript file to avoid false-positive antivirus flags in the VS Code Marketplace
  • CmdHelpChecker uses the standard IBMiComponent version mechanism — if the UDTF source changes in a future release, getRemoteState() will detect the stale version and update() will recompile automatically

Testing

Tested with Code for IBM i on IBM i 7.5. Hover response time dropped from 8–12 seconds (GENCMDDOC cold) to under 1 second (CMD_HELP).


Contributed by @BobCozzi

@bobcozzi bobcozzi force-pushed the feature/cmd-help-udtf branch from e263b1c to 63c4deb Compare May 21, 2026 19:49
@bobcozzi

bobcozzi commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

I saw PR70 after I created this, so I applied the same async pattern to CmdHelpChecker.
I would also suggest that you change the DBVIEW(*LIST) parameter to DBGVIEW(*NONE) so the C++ can be optimized--there's no use for a debug listing in this functions. If there is need to debug, the end-user can recompile with that option (the code is over on my github page anyway).

Introduces a new IBMiComponent (CmdHelpChecker) that installs a SQL
Table Function (CMD_HELP) backed by a C++ service program wrapping the
IBM i QUHRHLPT API. The UDTF is automatically compiled and installed into
the connection's tempLibrary on first connect.

The hover provider now tries CMD_HELP first (sub-second, no JVM required),
falls back to GENCMDDOC if the UDTF is unavailable or returns no data.

Changes:
- client/src/components/cmdHelp/cmdHelpChecker.ts  (new IBMiComponent)
- client/src/components/cmdHelp/cmdHelpCppSource.ts (embedded C++ source)
- client/src/components/cmdHelp/cmdHelpSqlSource.ts (UDTF DDL)
- client/src/gencmddoc.ts: add getCLDocParam() using CMD_HELP UDTF
- client/src/extension.ts: register CmdHelpChecker + getCLDocParam handler
- server/src/instance.ts: add getCLDocParam() LSP request helper
- server/src/providers/hover.ts: CMD_HELP fast path with GENCMDDOC fallback
- client/src/components/syntaxChecker/checker.ts: DBGVIEW(*NONE) cleanup

Signed-off-by: Bob Cozzi <cozzi@rpgiv.com>
@bobcozzi bobcozzi force-pushed the feature/cmd-help-udtf branch from 63c4deb to b79eac4 Compare May 21, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant